#!/usr/bin/ruby
# -*- ruby -*-
#
# http://www.reddit.com/r/dailyprogrammer/comments/16obmx/011613_challenge_117_intermediate_mayan_long_count/

require 'time'

STDIN.readlines.slice(1 .. -1).each do |line|
    line.strip!

    day, month, year = line.split(' ').map { |i| i.to_i }

    t = Time.local(year, month, day)

    days = t.to_i / (24 * 60 * 60)

    # 1 kin : 1 day
    # 1 uinal : 20 kin : 1 * 20 : 20 day
    # 1 tun : 18 uinal : 1 * 20 * 18 : 360 day
    # 1 katun : 20 tun : 1 * 20 * 18 * 20 : 7200 day
    # 1 baktun : 20 katun : 1 * 20 * 18 * 20 * 20 : 144000 day
    mayan_units = [144000, 7200, 360, 20, 1]
    mayan_days  = []

    until mayan_units.empty?
        mayan_unit = mayan_units.shift

        mayan = days / mayan_unit
        mayan_days.push(mayan)

        days -= (mayan * mayan_unit)
    end

    mayan_base = [12, 17, 16, 7, 5]

    puts mayan_days.zip(mayan_base).map { |(days, base)| (days + base).to_s }.join(".")
end
